import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { RoleQuery, RolePageResult, RoleForm, RoleDataForm } from "./types";
import { UserPageVO, UserQuery } from "../user/types";

/**
 * 获取角色分页数据
 *
 * @param queryParams
 */
export function getRolePage(
  queryParams?: RoleQuery
): AxiosPromise<RolePageResult> {
  return request({
    url: "/admin/role/index",
    method: "get",
    params: queryParams,
  });
}

export function getUserPage(queryParams?: UserQuery): AxiosPromise<UserPageVO> {
  return request({
    url: "/admin/role/user",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取角色下拉数据
 *
 * @param queryParams
 */
export function getRoleOptions(): AxiosPromise<OptionType[]> {
  return request({
    url: "/admin/role/getAll",
    method: "get",
  });
}

/**
 * 获取角色详情
 *
 * @param id
 */
export function getRoleForm(id: number): AxiosPromise<RoleDataForm> {
  return request({
    url: "/admin/role/edit",
    method: "get",
    params: { ids: id },
  });
}

/**
 * 添加角色
 *
 * @param data
 */
export function addRole(data: RoleForm) {
  return request({
    url: "/admin/role/add",
    method: "post",
    data: data,
  });
}

/**
 * 更新角色
 *
 * @param id
 * @param data
 */
export function updateRole(data: RoleForm) {
  return request({
    url: "/admin/role/edit",
    method: "put",
    data: data,
  });
}

/**
 * 批量删除角色，多个以英文逗号(,)分割
 *
 * @param ids
 */
export function deleteRoles(data: any) {
  return request({
    url: "/admin/role/del",
    method: "delete",
    data,
  });
}
